#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：turbo 
@File    ：utils.py
@Author  ：赵加响
@Date    ：2023/4/3 17:30 
@Desc    ：
"""
from apps.codetable.models import CodeTableDetail


def field_desc(request, field, value, model):
    """
    Args:
        request:
        field: 字段名
        value: 字段对应的值
        model: 模型名称

    Returns: 该语言下某个模型中字段值对应的说明
    """
    localization = getattr(request, 'LANGUAGE_CODE', None)
    if localization is None:
        localization = 'zh-hans'
    try:
        code_detail = CodeTableDetail.objects.get(code_table_head__field__exact=field,
                                                  code_table_head__model__exact=model,
                                                  localization=localization,
                                                  code__exact=value)
    except CodeTableDetail.DoesNotExist:
        return ''
    return code_detail.name
